<template>
    <div class="app-container">
      <!-- 角色列表 -->
      <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="角色名称" />

      <el-table-column prop="description" label="角色描述"/>

      <el-table-column prop="updateTime" label="更新时间" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/role/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      background
      layout="prev, pager, next"
      style="padding: 30px 0; text-align: center;"
      @current-change="getList"
    />
    </div>
</template>
<script>
import role from '@/api/management/role'

export default {
    data(){
        return{
            list:null,//查询之后接口返回的集合
            page:1,
            limit:8,
            total:0
        }
    },
    created(){//页面渲染之前执行
        this.getList()
    },
    methods:{//创建具体方法，调用user.js中的方法
        getList(page = 1){
            this.page = page
            role.pageRole(this.page,this.limit)
                .then(response =>{
                    this.list = response.data.rows
                    this.total = response.data.total
                })
        },
        removeDataById(id){
            this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //调用删除方法
                role.deleteRoleById(id)
                    .then(response =>{
                        //提示删除成功
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        //刷新列表
                        this.getList()
                    })
            })
        }
    }
}
</script>
